package com.banzhi.shop.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.adapter.InnerFragmentPagerAdapter;
import com.banzhi.shop.view.NoScrollViewPager;
import com.banzhi.shop.view.TitleBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/10.
 */
//拼团页面
public class GroupingFragment extends Fragment implements View.OnClickListener {

    private TitleBar mTitleBar;
    private ImageView mIvGrouping;
    private LinearLayout mLlGroupingSelect;
    private LinearLayout mLlMyGrouping;
    private NoScrollViewPager mViewPager;
    /*    private SmartRefreshLayout mSmartRefreshLayout1;
    private SmartRefreshLayout mSmartRefreshLayout2;
    private RecyclerView mRecyclerView1;
    private RecyclerView mRecyclerView2;*/
    // private List<String> mTitle = new ArrayList<String>();
    private List<Fragment> mFragment = new ArrayList<Fragment>();
    private InnerFragmentPagerAdapter mInnerFragmentPagerAdapter;
    private TextView mTvGroupingSelect;
    private TextView mTvMyGrouping;
    private ImageView mIvUnderline1;
    private ImageView mIvUnderline2;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getContext()).inflate(R.layout.fragment_grouping, container, false);
        initView(view);
        initListener();
        return view;
    }

    private void initView(View view) {
        mTitleBar = (TitleBar) view.findViewById(R.id.tb_grouping);
        mTitleBar.setTitle("拼团");
        mIvGrouping = (ImageView) view.findViewById(R.id.iv_grouping);
        mLlGroupingSelect = (LinearLayout) view.findViewById(R.id.ll_grouping_select);
        mTvGroupingSelect = (TextView) view.findViewById(R.id.tv_grouping_select);
        mLlMyGrouping = (LinearLayout) view.findViewById(R.id.ll_my_grouping);
        mTvMyGrouping = (TextView) view.findViewById(R.id.tv_my_grouping);
        mViewPager = (NoScrollViewPager) view.findViewById(R.id.viewpager);
        mIvUnderline1 = (ImageView) view.findViewById(R.id.iv_underline1);
        mIvUnderline2 = (ImageView) view.findViewById(R.id.iv_underline2);


       mFragment.add(new GroupingSelectFragment());
     //  mFragment.add(new College_DaifaFragment());

     //   mFragment.add(new MyGroupingFragment());
        mInnerFragmentPagerAdapter = new InnerFragmentPagerAdapter(getFragmentManager(), mFragment);
        mViewPager.setAdapter(mInnerFragmentPagerAdapter);
/*        mSmartRefreshLayout1 = (SmartRefreshLayout) view.findViewById(R.id.refreshLayout1);
        mRecyclerView1 = (RecyclerView) view.findViewById(R.id.recycler_view1);
        mSmartRefreshLayout2 = (SmartRefreshLayout) view.findViewById(R.id.refreshLayout2);
        mRecyclerView2 = (RecyclerView) view.findViewById(R.id.recycler_view2);*/
    }

    private void initListener() {
        mLlGroupingSelect.setOnClickListener(this);
        mLlMyGrouping.setOnClickListener(this);


    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_grouping_select:
                mTvGroupingSelect.setTextColor(ContextCompat.getColor(getContext(), R.color.themeColor));
                mIvUnderline1.setVisibility(View.VISIBLE);
                mViewPager.setCurrentItem(0, false);
                mTvMyGrouping.setTextColor(ContextCompat.getColor(getContext(), R.color.black));
                mIvUnderline2.setVisibility(View.GONE);
                break;
            case R.id.ll_my_grouping:
                mTvGroupingSelect.setTextColor(ContextCompat.getColor(getContext(), R.color.black));
                mIvUnderline1.setVisibility(View.GONE);
                mViewPager.setCurrentItem(1, false);
                mTvMyGrouping.setTextColor(ContextCompat.getColor(getContext(), R.color.themeColor));
                mIvUnderline2.setVisibility(View.VISIBLE);
                break;
        }

    }
}
